// pages/contrast_results/results.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    yearContrastArr: {
      type: Array,
    },
    current: {
      type: Number,
      observer: "tips"
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    tips: function () {
      var that = this
      var yearContrastArr = that.data.yearContrastArr
      for (var i = 0, len = yearContrastArr.length; i < len; i++) {
        if (that.healthy(yearContrastArr[i])) {
          yearContrastArr[i].healthy = true
        }
        if (that.unhealthy(yearContrastArr[i])) {
          yearContrastArr[i].unhealthy = true
        }
      }
      that.setData({ yearContrastArr: yearContrastArr })
    },
    //健康
    healthy: function (arr) {
      for (let j = 0, leng = arr.labels.length; j < leng; j++) {
        if (arr.labels[j].abnormal == 0) {
          return false
        }
      }
      return true
    },
    //不健康
    unhealthy: function (arr) {
      for (let j = 0, leng = arr.labels.length; j < leng; j++) {
        if (arr.labels[j].abnormal == 1) {
          return false
        }
      }
      return true
    },
  },
  ready: function () {
    this.tips()
  }
})
